<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/vue@3"></script>
    <script src="https://unpkg.com/vue-router@4"></script>
</head>

<body>
    <div id="app" class="demo">
       
        <!-- 1.2根据动态属性，跳转到相同的组件 -->
        <router-link to="/one/nihao/user/1">/one/nihao/user/1</router-link><br>
        <router-link to="/one/hello/user/2">/one/hello/user/2</router-link><br>
        <!-- 需要完整匹配 -->
        <router-link to="/one/world">/one/world</router-link><br>
        
        <router-view></router-view>
    </div>

    <template id="one">

        <hr>
        模板一<br>
        <!-- 1.3获取到组件路径上参数 -->
        param1:{{$route.params.param1}} <br>
        id1:{{$route.params.id1}}
    </template>

</body>
<script>

    const oneConfig = {
        template:'#one',

    };
    const twoConfig = {
        template:'#two',

    };

    const HelloVueApp = {
        data() {
            return {

            }
        },
        components:{
            one:oneConfig,
            two:twoConfig
        }
    }

     //定义路由
     const routes = [
        //1.设置路径匹配规则
        { path: '/one/:param1/user/:id1', component: oneConfig },
    ];
    //定义vueRouter对象
    const router = VueRouter.createRouter({
        // 4. 内部提供了 history 模式的实现。为了简单起见，我们在这里使用 hash 模式。
        history: VueRouter.createWebHashHistory(),
        routes
    });
    const app = Vue.createApp(HelloVueApp);
    //使用路由
    app.use(router);
    app.mount('#app')
</script>

</html>